package com.bocek.chakmapoint.view;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JPanel;

import com.bocek.chakmapoint.controller.MainController;
import com.bocek.chakmapoint.view.menubar.MenubarView;
import com.bocek.chakmapoint.view.slide.SlideView;
import com.bocek.chakmapoint.view.toolbar.ToolbarView;

import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.border.EtchedBorder;
import javax.swing.JMenuBar;
import javax.swing.border.BevelBorder;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * Main view and application entry point.
 * 
 * @author  Baris Sencan
 * @version 1.3
 */
public class MainView extends JFrame {
	private static final long serialVersionUID = -7162359975059451150L;
	private static final MainView instance = new MainView();
	private static JLabel lblTitle;

	/**
	 * Launch the application.
	 * 
	 * @requires String[]
	 * @modifies Nothing.
	 * @effects  Nothing.
	 */
	public static void main(String[] args) {
		
		EventQueue.invokeLater(new Runnable() {
			
			public void run() {
				
				try {
					MainView.getInstance().setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public static MainView getInstance() {
		return instance;
	}
	
	private MainView() {
		super("ChakmaPoint 1.0 - By BOCEK Ltd.");
		
		setTitle("ChakmaPoint 1.0 - By BOCEK Ltd.");
		setBounds(100, 100, 800, 645);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		getContentPane().setLayout(null);
		
		JPanel slidePanel = SlideView.getInstance();
		slidePanel.setBorder(new LineBorder(new Color(0, 0, 0)));
		slidePanel.setBounds(141, 101, 640, 480);
		getContentPane().add(slidePanel);
		getContentPane().setComponentZOrder(slidePanel, 0);
		
		JPanel menubarPanel = MenubarView.getInstance();
		menubarPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		menubarPanel.setBounds(6, 101, 123, 480);
		getContentPane().add(menubarPanel);
		
		JPanel toolbarPanel = ToolbarView.getInstance();
		toolbarPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		toolbarPanel.setBounds(6, 6, 775, 63);
		getContentPane().add(toolbarPanel);
		
		JLabel lblNewLabel = new JLabel("Current Slide Title:");
		lblNewLabel.setBounds(6, 73, 123, 16);
		getContentPane().add(lblNewLabel);
		
		lblTitle = new JLabel("");
		lblTitle.setBounds(141, 73, 640, 16);
		getContentPane().add(lblTitle);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenuItem mntmFile = new JMenu("File");
		menuBar.add(mntmFile);
		
		JMenuItem mntmSave = new JMenuItem("Save");
		mntmSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				MainController.getInstance().saveButtonPressed();
			}
		});
		mntmFile.add(mntmSave);
		
		JMenuItem mntmLoad = new JMenuItem("Load");
		mntmLoad.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainController.getInstance().loadButtonPressed();
			}
		});
		mntmFile.add(mntmLoad);
	}
	
	public void setTitleLabel(String title) {
		lblTitle.setText(title);
	}
}
